package com.opgea.crm.web.form;

import com.opgea.crm.common.util.DateUtil;
import com.opgea.crm.domain.entities.Activity;
import com.opgea.crm.domain.entities.Employee;
import com.opgea.crm.domain.entities.Lead;
import com.opgea.crm.domain.entities.Opportunity;

public class ActivityForm {

	private String activityId;
	private String leadId;
	private String subject;
	private String dueDate;
	private String duration;
	private String relatedCompany;
	private String relatedTo;
	private String firstName;
	private String middleInitial;
	private String lastName;
	
	private String opportunity;
	private long opportunityId;
	
	private String notes;
	
	private String reminder;
	private String reminderDate;
	
	private String activityType;
	private long activityTypeId;
	
	private String priority;
	private long priorityId;
	
	private String status;
	private long statusId;
	
	private String stage;
	private long stageId;
	
	private String assignedTo;
	private long assignedToId;
	//Extra
	private String activitySearchCriteria;
	private String activityCriteriaValue;

	public void setActivityId(String activityId) {
		this.activityId = activityId;
	}
	public String getActivityId() {
		return activityId;
	}
	public void setLeadId(String leadId) {
		this.leadId = leadId;
	}
	public String getLeadId() {
		return leadId;
	}
	
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getDueDate() {
		return dueDate;
	}
	public void setDueDate(String dueDate) {
		this.dueDate = dueDate;
	}
	public void setDuration(String duration) {
		this.duration = duration;
	}
	public String getDuration() {
		return duration;
	}	
	public String getRelatedCompany() {
		return relatedCompany;
	}
	public void setRelatedCompany(String relatedCompany) {
		this.relatedCompany = relatedCompany;
	}
	public String getRelatedTo() {
		return relatedTo;
	}
	public void setRelatedTo(String relatedTo) {
		this.relatedTo = relatedTo;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getMiddleInitial() {
		return middleInitial;
	}
	public void setMiddleInitial(String middleInitial) {
		this.middleInitial = middleInitial;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getOpportunity() {
		return opportunity;
	}
	public void setOpportunity(String opportunity) {
		this.opportunity = opportunity;
	}
	public void setOpportunityId(long opportunityId) {
		this.opportunityId = opportunityId;
	}
	public long getOpportunityId() {
		return opportunityId;
	}
	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	
	public String getActivityType() {
		return activityType;
	}
	public void setActivityType(String activityType) {
		this.activityType = activityType;
	}
	public void setActivityTypeId(long activityTypeId) {
		this.activityTypeId = activityTypeId;
	}
	public long getActivityTypeId() {
		return activityTypeId;
	}
	public String getPriority() {
		return priority;
	}
	public void setPriority(String priority) {
		this.priority = priority;
	}
	public void setPriorityId(long priorityId) {
		this.priorityId = priorityId;
	}
	public long getPriorityId() {
		return priorityId;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public void setStatusId(long statusId) {
		this.statusId = statusId;
	}
	public long getStatusId() {
		return statusId;
	}
	public String getStage() {
		return stage;
	}
	public void setStage(String stage) {
		this.stage = stage;
	}
	public void setStageId(long stageId) {
		this.stageId = stageId;
	}
	public long getStageId() {
		return stageId;
	}
	public String getAssignedTo() {
		return assignedTo;
	}
	public void setAssignedTo(String assignedTo) {
		this.assignedTo = assignedTo;
	}
	public void setAssignedToId(long assignedToId) {
		this.assignedToId = assignedToId;
	}
	public long getAssignedToId() {
		return assignedToId;
	}
	public String getReminderDate() {
		return reminderDate;
	}
	public void setReminderDate(String reminderDate) {
		this.reminderDate = reminderDate;
	}

	public void setActivitySearchCriteria(String activitySearchCriteria) {
		this.activitySearchCriteria = activitySearchCriteria;
	}
	public String getActivitySearchCriteria() {
		return activitySearchCriteria;
	}
	public String getActivityCriteriaValue() {
		return activityCriteriaValue;
	}
	public void setActivityCriteriaValue(String activityCriteriaValue) {
		this.activityCriteriaValue = activityCriteriaValue;
	}

	public String isReminder() {
		return reminder;
	}
	public void setReminder(String reminder) {
		this.reminder = reminder;
	}
	
	public String getReminder() {
		return reminder;
	}

	public ActivityForm(){}
	
	public ActivityForm(Activity activity){
		Employee assignedTo = activity.getAssignTo();
		Lead lead = activity.getLead();
		Opportunity opportunity = activity.getOpportunity();		
		
		this.setActivityId(String.valueOf(activity.getId()));
		this.setLeadId(String.valueOf(lead.getId()));
		this.setFirstName(lead.getFirstName());
		this.setMiddleInitial(lead.getMiddleInitial());
		this.setLastName(lead.getLastName());

		if(activity.getActivityType() != null){
			this.setActivityType(activity.getActivityType().getFieldValue());
			this.setActivityTypeId(activity.getActivityType().getId());
		}
		if(opportunity != null){
			this.setOpportunity(opportunity.getOpportunityTitle());
			this.setOpportunityId(opportunity.getId());
		}
		if(activity.getActivityStage() != null){
			this.setStage(activity.getActivityStage().getFieldValue());
			this.setStageId(activity.getActivityStage().getId());
		}
		if(activity.getActivityStatus() != null){
			this.setStatus(activity.getActivityStatus().getFieldValue());
			this.setStatusId(activity.getActivityStatus().getId());
		}
		if(activity.getPriority() != null){
			this.setPriority(activity.getPriority().getFieldValue());
			this.setPriorityId(activity.getPriority().getId());
		}
		if(assignedTo != null){
			this.setAssignedTo(assignedTo.getFirstName());
			this.setAssignedToId(assignedTo.getId());
		}		
		
		this.setSubject(activity.getSubject());
		this.setDueDate(DateUtil.dateToString(activity.getScheduledDate()));
		this.setReminderDate(DateUtil.dateToString(activity.getReminderDate()));
		this.setDuration(String.valueOf(activity.getDuration()));
		this.setNotes(activity.getNote());
		
	}
}
